<!DOCTYPE html>
<html>
    {include file="Widgets/head" /}
    <body class="gray-bg">
        <div class="wrapper wrapper-content animated fadeInUp">
            <div class="row">
                <div class="col-sm-12">
                    <div class="ibox">
                        <div class="ibox-title">
                            <h3>资产管理-列表</h3>
                        </div>
                        <div class="ibox-content">
                            <form action="" method="get" class="form-horizontal">
                                <input type="hidden" name="status" value="{$status}">
                                <div class="form-group">
                                    <label class="col-sm-1 control-label" style="text-align:center;" for="code">资产编号：</label>
                                    <div class="col-sm-2 m-b-xs">
                                        <input type="text" id="code" name="code" value="{$code}" class="form-control input-s-sm inline" placeholder="资产编号">
                                    </div>
                                    <label class="col-sm-1 control-label" style="text-align:center;" for="name">资产名称：</label>
                                    <div class="col-sm-2 m-b-xs">
                                        <input type="text" id="name" name="name" value="{$name}" class="form-control input-s-sm inline" placeholder="资产名称">
                                    </div>
                                    <label class="col-sm-1 control-label" style="text-align:center;" for="status">状态：</label>
                                    <div class="col-sm-2 m-b-xs">
                                        <select id="status" name="status" class="form-control input-s-sm inline">
                                            <option value="0" {if($status == 0)} selected {/if}>全部</option>
                                            {foreach $status_list as $key => $val} 
                                            <option value="{$key}" {if($key == $status)} selected {/if}>{$val}</option>
                                            {/foreach}
                                        </select>
                                    </div>
                                    <label class="col-sm-1 control-label" style="text-align:center;" for="duration">放款期限：</label>
                                    <div class="col-sm-2 m-b-xs">
                                        <select id="duration" name="duration" class="form-control input-s-sm inline">
                                            <option value="0" {if($duration == 0)} selected {/if}>全部</option>
                                            {foreach $term_list as $term} 
                                            <option value="{$term}" {if($term == $duration)} selected {/if}>{$term}</option>
                                            {/foreach}
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-1 control-label" style="text-align:center;" for="capital_min">资产总额：</label>
                                    <div class="col-sm-2 m-b-xs">
                                        <input type="text" id="capital_min" name="capital_min" value="{$capital_min}" class="form-control input-s-sm inline">
                                    </div>
                                    <label class="col-sm-1 control-label" style="text-align:center;" for="capital_max">-</label>
                                    <div class="col-sm-2 m-b-xs">
                                        <input type="text" id="capital_max" name="capital_max" value="{$capital_max}" class="form-control input-s-sm inline">
                                    </div>
                                    <label class="col-sm-1 control-label" style="text-align:center;" for="type">资产类型：</label>
                                    <div class="col-sm-2 m-b-xs">
                                        <select id="type" name="type" class="form-control input-s-sm inline">
                                            <option value="0" {if($type == 0)} selected {/if}>全部</option>
                                            {foreach ($type_list as $key => $val)} 
                                            <option value="{$key}" {if($key == $type)} selected {/if}>{$val}</option>
                                            {/foreach}
                                        </select>
                                    </div>
                                    <div class="col-sm-1 m-b-xs">
                                        <button class="btn btn-primary" type="submit">查询</button>
                                    </div>
                                </div>
                            </form>
                            <div class="hr-line-dashed"></div>
                            <table class="table table-bordered table-hover">
                                <thead>
                                    <tr>
                                        <th>序号</th>
                                        <th>资产编号</th>
                                        <th>资产名称</th>
                                        <th>资产类型</th>
                                        <th>资产本金 </th>
                                        <th>总成本利率 </th>
                                        <th>放款期限（天）</th>
                                        <th>还款方式</th>
                                        <th>状态</th>
                                        <th>更新时间</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {if ($list)}
                                        {foreach $list as $key => $val} 
                                            <tr class="gradeA odd">
                                                <td>{$key + 1}</td>
                                                <td>{$val['code']}</td>
                                                <td>{$val['name']}</td>
                                                <td>{$val['type']}</td>
                                                <td>{$val['capital']}</td>
                                                <td>{$val['interest_rate']}</td>
                                                <td>{$val['duration']}</td>
                                                <td>{$val['repayment_type']}</td>
                                                <td>{$val['status_name']}</td>
                                                <td>
                                                    {if (strtotime($val['update_time']))}
                                                        {$val['update_time']}
                                                    {/if}
                                                </td>
                                                <td>
                                                    {if ($val['status'] == 1)}
                                                        <a href="{:url('Assets/editMain',['id'=>$val['id']])}" class="btn btn-primary">编辑</a>
                                                        <a data-toggle="modal" data-id="{$val['id']}" data-target=".sc-modal-sm"
                                                            type="button" class="btn btn-primary">删除
                                                        </a>
                                                    {else /}
                                                        <a href="{:url('Assets/show',['id'=>$val['id']])}" class="btn btn-info">详情</a>
                                                    {/if}
                                                </td>
                                            </tr>
                                        {/foreach}                            
                                    {else /}
                                        <tr class="gradeA odd">
                                            <td style="text-align:center;" colspan="11">没有找到符合条件的记录</td>
                                        </tr>
                                    {/if}
                                </tbody>
                            </table>
                            {//分页}
                            <div>
                                <div class="row">
                                    {$paginator}
                                </div>
                            </div>
                            <div class="row">
                                <div class="dropdown col-sm-2">
                                    <button type="button" class="btn btn-primary dropdown-toggle" id="dropdownMenu1" data-toggle="dropdown">添加资产<span class="caret"></span></button>
                                    <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
                                        {foreach ($type_list as $type => $name)}
                                        {if ($type > 1)}
                                        <li role="presentation" class="divider"></li>
                                        {/if}
                                        <li role="presentation">
                                            <a role="menuitem" tabindex="-1" href="{:url('Assets/add', ['type'=>$type])}">
                                                {$name}
                                            </a>
                                        </li>
                                        {/foreach}
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="modal fade sc-modal-sm" style="margin-top:10%;" tabindex="-1" role="dialog"
            aria-labelledby="mySmallModalLabel">
           <div class="modal-dialog modal-sm" style="width:500px;">
               <div class="modal-content">
                   <div class="modal-body">
                       <div class="modal-header">
                           <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                       aria-hidden="true">×</span></button>
                           <h4 class="modal-title" id="mySmallModalLabel">删除资产</h4>
                       </div>
                       <div class="modal-body">
                           <h3>确定要删除此资产吗？</h3>
                           <form id="delete-ads">
                               <input id="id" name="id" type="hidden" value="">
                           </form>
                       </div>
                       <div class="modal-footer">
                           <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                           <button type="button" class="btn btn-primary delete-ads">确定</button>
                       </div>
                   </div>
               </div>
           </div>
       </div>
        
        <script>
            $(function () {
                $('.sc-modal-sm').on('show.bs.modal', function (event) {
                    var button = $(event.relatedTarget);
                    var id = button.data('id');
                    var modal = $(this);
                    modal.find('.modal-body input#id').val(id);
                });
                $('.delete-ads').on('click', function () {
                    $.ajax({
                        type: 'POST',
                        url: "{:url('Assets/delete')}",
                        data: $('#delete-ads').serialize(),
                        dataType: 'json',
                        success: function (data) {
                            if (data.code == 1) {
                                window.location.href = window.location.href;
                            } else {
                                alert(data.message)
                            }
                        },
                        error: function (xhr, type) {
                            alert('Ajax error!')
                        }
                    });
                });
            });
        </script>
    </body>
</html>
